package com.mybatisPlus.controller;

import com.mybatisPlus.common.Result;
import com.mybatisPlus.servie.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;

    //上传文件
    @RequestMapping("/uploadFile")
    public Result uploadFile(MultipartFile file, HttpServletRequest request){
        return fileService.uploadFile(file,request);
    }

    //分页获取文件列表
    @GetMapping("/getFileList")
    public Result getFileList(int current,HttpServletRequest request){
        return fileService.getFileList(current,request);
    }

    //下载文件
    @GetMapping("/downloadFile")
    public void downloadFile(String name, HttpServletResponse response){
        fileService.downloadFile(name,response);
    }

    //删除文件
    @GetMapping("/delFile")
    public Result delFile(String name){
        return fileService.delFile(name);
    }
}
